package com.gitee.cui.client.builder;

import com.gitee.cui.client.client.ClientSession;
import com.gitee.cui.common.common.bean.User;
import com.gitee.cui.common.common.bean.msg.ProtoMsg;

/**
 * 登录消息构建器
 * @author cuiqingqiang
 * @version 1.0
 * @date 2021/10/27 15:20
 **/
public class LoginMsgBuilder extends BaseBuilder {

    /**
     * 用户信息
     */
    private User user;

    public LoginMsgBuilder (User user, ClientSession session) {
        super(ProtoMsg.HeadType.LOGIN_REQUEST, session);
        this.user = user;
    }

    /**
     * 构建登录消息
     * @return 登录消息
     */
    public ProtoMsg.Message build() {
        ProtoMsg.Message message = buildCommon(-1);
        ProtoMsg.LoginRequest.Builder lb = ProtoMsg.LoginRequest.newBuilder()
                .setDeviceId(user.getDevId())
                .setPlatform(user.getPlatform().ordinal())
                .setToken(user.getToken())
                .setUid(user.getUid());
        return message.toBuilder().setLoginRequest(lb).build();
    }

    /**
     * 获取登录消息
     * @param user 用户信息
     * @param session session信息
     * @return 登录消息
     */
    public static ProtoMsg.Message buildLoginMsg(User user, ClientSession session) {
        LoginMsgBuilder loginMsgBuilder = new LoginMsgBuilder(user, session);
        return loginMsgBuilder.build();
    }
}
